<template>
  <div class="search-history">
    <van-cell title="搜索历史">
      <span
        @click="
          $emit('removeAllHis')
          isDeleteShow = false
        "
        >全部删除</span
      >
      &nbsp;&nbsp;
      <span @click="isDeleteShow = false" v-if="isDeleteShow">完成</span>
      <van-icon name="delete" @click="isDeleteShow = true" v-else />
    </van-cell>
    <van-cell
      v-for="(v, ind) in searchHistories"
      :key="ind"
      :title="v"
      @click="clickHisLineFn(ind, v)"
    >
      <van-icon name="close" v-if="isDeleteShow" />
    </van-cell>
  </div>
</template>

<script>
export default {
  name: 'searchHistory',
  props: {
    searchHistories: {
      type: Array,
      required: true
    }
  },
  data () {
    return {
      // 是否为删除状态
      isDeleteShow: false
    }
  },

  methods: {
    // 点击历史条目
    clickHisLineFn (ind, v) {
      if (this.isDeleteShow) {
        // 删除某条记录
        this.$emit('removeHis', ind)
      } else {
        this.$emit('onSearch', v)
      }
    }
  }
}
</script>

<style></style>
